package 字符串练习;

public class text {
    public static void main(String[] args) {
        String s = "abcdefgb";

        //获取索引为2的字符
        char c = s.charAt(2);
        System.out.println(c);

        //获取字符为“b”的索引，第一次出现的索引
        int i = s.indexOf("b");
        System.out.println(i);

        //获取从2索引开始,字符为“b”的索引
        int i1 = s.indexOf("b", 2);
        System.out.println(i1);

        //获取字符“b”最后一次出现的索引
        int i2 = s.lastIndexOf("b");
        System.out.println(i2);

        //替换字符，所有的a
        String r = s.replace("b", "k");
        System.out.println(r);

        //截取字符
        String substring = s.substring(3, 4);//包头不包尾，即3索引
        System.out.println(substring);

        String substring1 = s.substring(0, 4);
        System.out.println(substring1);

        String substring2 = s.substring(0, s.length() / 2);
        System.out.println(substring2);

        String substring3 = s.substring(s.length() / 2);
        System.out.println(substring3);
    }
}
